<template>
	<view>
		<view class="sh-userinfo-box" :style="'background-image: url('+$IMG_URL+'/imgs/user/user_bg.jpg)'">
			<view class="head-wrap">
				<!-- 设置、消息 -->
				<view class="install-information">
					<view class="install-div" @tap="$Router.push('/pages/user/info')">
            <image src="/static/images/install.png"></image>
						<span>设置</span>
					</view>
					<view class="information-div" @tap="$Router.push('/pages/notification/list')">
            <image v-if="userInfo.is_information==0" src="/static/images/information.png"></image>
            <image v-if="userInfo.is_information==1" src="/static/images/information2.png"></image>
						<span>消息</span>
					</view>
				</view>

        <view class="tag-grade">
          <!-- 等级 -->
          <view class="grade-tag tag-box u-flex">
            <image class="tag-img" :src="userInfo.level.image" mode=""></image>
            <text class="tag-title g1">{{userInfo.level.title}}</text>
          </view>
        </view>
				
        <view class="info-box" @tap="$Router.push('/pages/user/info')">
          <view class="head-img-wrap" >
            <image class="head-img" :src="userInfo.avatar || $IMG_URL + '/imgs/base_avatar.png'" mode="aspectFill"></image>
          </view>
          <view class="u-flex u-col-center" @tap="$Router.push('/pages/user/info')">
            <view class="user-name" v-if="userInfo && userInfo.nickname">{{ userInfo.nickname}}</view>
            <view class="user-name" v-else-if="userInfo && !userInfo.nickname">点击完善资料</view>
            <view class="user-name" v-else>请登录</view>
          </view>
        </view>
			</view>
		</view>
		<!-- 绑定手机 -->
		<!-- <view class="notice-box u-flex u-row-between u-p-30" v-if="userInfo.verification && !userInfo.verification.mobile" @tap="bindMobile">
			<view class="notice-detail">点击绑定手机号，确保账户安全</view>
			<button class="u-reset-button bindPhone">去绑定</button>
		</view> -->
		<!-- 更新信息 -->
		<!-- <view class="cu-modal" :class="{ show: showModal }" @tap="showModal = false">
			<view class="cu-dialog" style="width: 600rpx;">
				<view class="modal-box">
					<view class="modal-head">提示</view>
					<view class="modal-content">更新微信信息？</view>
					<view class="modal-bottom u-flex u-col-center">
						<button class="u-reset-button modal-btn cancel-btn" :hover-stay-time="100" hover-class="btn-hover" @tap="showModal = false">取消</button>
						<button class="u-reset-button  modal-btn save-btn" :hover-stay-time="100" hover-class="btn-hover" @tap="refreshWechatUser">确定</button>
					</view>
				</view>
			</view>
		</view> -->
	</view>
</template>

<script>
/**
 * 自定义之个人信息
 * @property {Object} detail - 个人信息
 */
import { mapMutations, mapActions, mapState, mapGetters } from 'vuex';
import wechat from '@/shopro/wechat/wechat';
export default {
	components: {},
	data() {
		return {
			showModal: false,
			platform: this.$platform.get(), //当前平台。
			isFixed: false,
			navBackground: {
				background: 'none'
			}
		};
	},
	mounted() {},
	props: {
		detail: {},
		scrollTop: {
			type: Number,
			default: 0
		},
	},
	watch: {
		scrollTop(val) {
			let backgroundText = this.detail.image ? `url(${this.detail.image})` : this.detail.color;
			this.isFixed = val > 50 ? true : false;
			this.navBackground.background = val > 50 ? backgroundText : 'none';
		}
	},
	computed: {
		...mapGetters(['isLogin', 'userInfo', 'userOtherData']),
		showRefresh() {
			if (this.isLogin) {
				if (this.platform === 'wxOfficialAccount') {
					return this.userInfo.verification?.wxOfficialAccount;
				}
				if (this.platform === 'wxMiniProgram') {
					return this.userInfo.verification.wxMiniProgram;
				}
				if (this.platform === 'App') {
					return this.userInfo.verification.wxOpenPlatform;
				}
			}
			return false;
		}
	},
	methods: {
		...mapActions(['getUserInfo', 'showAuthModal']),
		jump(path, query) {
			this.$Router.push({
				path: path,
				query: query
			});
		},
		// 点击分享
		onShare() {
			this.$emit('onShare');
		},
		// 同步用户信息
		async refreshWechatUser() {
			this.showModal = false;
			let token = await wechat.refresh();
			token && this.getUserInfo(token);
		},
		// 跳转门店
		goStore() {
			if (this.userOtherData.store_id) {
				uni.setStorageSync('storeId', this.userOtherData.store_id);
				this.jump('/pages/app/merchant/index', { storeId: this.userOtherData.store_id });
			} else {
				if (uni.getStorageSync('storeId')) {
					this.jump('/pages/app/merchant/index');
				} else {
					this.jump('/pages/app/merchant/list');
				}
			}
			//  #ifdef MP-WEIXIN
			this.$store.commit('subscribeMessage', 'store');
			//  #endif
		},
		// 绑定手机号
		bindMobile() {
			this.showAuthModal('bindMobile');
		}
	}
};
</script>

<style lang="scss">
// 更新信息
.modal-box {
	width: 600rpx;
	.btn-hover {
		background-color: rgb(230, 230, 230);
	}
	.modal-head {
		padding-top: 48rpx;
		font-weight: 500;
		text-align: center;
		color: $u-main-color;
	}
	.modal-content {
		padding: 48rpx;
		font-size: 30rpx;
		text-align: center;
		color: $u-content-color;
	}
	.modal-bottom {
		.modal-btn {
			flex: 1;
			height: 100rpx;
			line-height: 100rpx;
			font-size: 32rpx;
			box-sizing: border-box;
			cursor: pointer;
			text-align: center;
			border-radius: 4rpx;
		}
		.cancel-btn {
			color: #444;
		}
		.save-btn {
			color: #444;
		}
	}
}
.sh-userinfo-box {
	position: relative;
  height: 300rpx;
  background-size: cover;
  background-position: center;
  overflow: hidden;
	.head-wrap {
    height: 400rpx;
		.merchant-btn {
			width: 178rpx;
			height: 64rpx;
			line-height: 64rpx;
			background-color:#bebebe;
			border-radius: 32rpx;
			font-size: 26rpx;
			font-weight: 500;
			color: #444;
		}
	}

  .info-box {
    position: absolute;
    right: 30rpx;
    bottom: 15rpx;
    width: 300rpx;
    display: flex;
    justify-content: flex-end;
    flex-direction: column;
    align-items: flex-end;
    .head-img-wrap {
      position: relative;
      .refresh-btn {
        position: absolute;
        padding: 0;
        background: none;
        width: 40rpx;
        height: 40rpx;
        border-radius: 50%;
        background-color:#bebebe;
        top: -10rpx;
        right: 10rpx;
      }
    }
    .head-img {
      width: 100rpx;
      height: 100rpx;
      border-radius: 50%;
      background-color:#bebebe;
      overflow: hidden;
      border: 3rpx solid rgba(255, 255, 255, 1);
    }
    .sex-img{
      width: 42rpx;
      height: 42rpx;
      position: absolute;
      bottom: 8rpx;
      right: 35rpx;
    }
    .user-name {
      margin-top: 5rpx;
      font-size: 24rpx;
      font-weight: 500;
      color: #fff;
      width: 300rpx;
      white-space: nowrap;
      text-align: right;
    }
    .user-tel{
      color: #fff;
      margin-top: 10rpx;
    }
  }
  .tag-grade{
    position: absolute;
    top: 30rpx;
    left: 10rpx;
    .tag-img{
      margin-right: 10rpx;
    }
  }
  .tag-box {
    // background: rgba(0, 0, 0, 0.2);
    // border-radius: 22rpx;
    padding-left: 20rpx;
    .tag-img {
      width: 40rpx;
      height: 40rpx;
      display: inline-block;
      border-radius: 50%;
    }
    .tag-title {
      font-size: 20rpx;
      font-weight: 500;
      color: rgba(255, 255, 255, 1);
      line-height: 40rpx;
      padding: 0 10rpx;
    }
    .g1{
      font-size: 21rpx;
      color: #fff;
    }
    .g2{
      font-size: 21rpx;
      color: #fff;
    }
    .g3{
      font-size: 21rpx;
      color: #fff;
    }
    .g4{
      font-size: 21rpx;
      color: #fff;
    }
    .g5{
      font-size: 21rpx;
      color: #fff;
    }
  }
  .code-btn {
    padding: 30rpx;
    .icon-qrcode {
      font-size: 50rpx;
      color: #444;
    }
  }
	.wallet {
		font-size: 20rpx;
		padding-left: 140rpx;
		.money {
			margin-right: 40rpx;
		}
	}
}
// 绑定微信公众号
.notice-box {
	width: 750rpx;
	height: 70rpx;
	background: rgba(253, 239, 216, 1);
	padding: 0 35rpx;

	.notice-detail {
		font-size: 24rpx;

		font-weight: 400;
		color: rgba(204, 149, 59, 1);
	}

	.bindPhone {
		width: 135rpx;
		line-height: 52rpx;
		background: linear-gradient(90deg, rgba(233, 180, 97, 1), rgba(238, 204, 137, 1));
		border-radius: 26rpx;
		padding: 0;
		font-size: 26rpx;

		font-weight: 500;
		color: rgba(255, 255, 255, 1);
	}
}

.install-information{
	display: flex;
	justify-content: flex-end;
	margin-top: 20rpx;
	margin-bottom: 20rpx;
	.install-div{
		display: flex;
		flex-direction: column;
		flex-wrap: nowrap;
		align-items: center;
		margin-right: 50rpx;
	}
	.information-div{
		display: flex;
		flex-direction: column;
		flex-wrap: nowrap;
		align-items: center;
		margin-right: 50rpx;
	}
	
	image{
		width: 41rpx;
		height: 41rpx;
	}
	span{
		font-size: 23rpx;
		color: #fff;
		margin-top: 8rpx;
	}
}
</style>
